import * as types from "./action-types"
import { fromJS } from "immutable"
const HeaderInit = fromJS({ focused: false, mouseIn: false, list: [], currentPage: 2, totalPages: 1 })
// export const Header = (state = HeaderInit, action) => {
//     return state;
// }

export default function (state = HeaderInit, action) {
    switch (action.type) {
        case types.CLICK_SEARCH_FOCUS:
            return state.set('focused', true)
        case types.CLICK_SEARCH_ONBLUR:
            return state.set('focused', false)
        case types.GET_SEARCH_INFO:
            return state.merge({
                list: action.data,
                totalPages: action.totalPages
            })
        case types.MOVE_SEARCH_IN:
            return state.set('mouseIn', true)
        case types.MOVE_SEARCH_OUT:
            return state.set('mouseIn', false)
        case types.CHANGE_SEARCH_PAGES: {
            let pages = state.get("currentPage")
            const totalPages = state.get("totalPages")
            if (pages + 1 === totalPages) {
                return state.set("currentPage", 0)
            } else {
                return state.set("currentPage", pages + 1)
            }
        }


        default:
            return state;
    }

}